<template>
  <!--  背景不随缩放变化-->
  <div>
    <div class="el-container"></div>
    <div class="card">
      <h3 class="title2">用户登录</h3>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="20px" class="demo-ruleForm">
        <el-form-item prop="adminName">
          <el-input v-model="ruleForm.adminName" style="width: 340px;height: 20px" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item prop="adminPasswd" style="height: 20px">
          <el-input v-model="ruleForm.adminPasswd" show-password style="width: 340px;" placeholder="请输入密码"></el-input>
        </el-form-item>
        <!--      <div style="border: 1px solid red;height: 30px;width: 340px;margin-left: 20px">-->
        <el-form-item style="height: 15px;">
          <el-checkbox style="float: left;color: #fff" v-model="password">记住密码</el-checkbox>
          <!--        <el-button type="text" style="float: right">立即注册</el-button>-->
        </el-form-item>
        <!--      </div>-->
        <el-form-item>
          <!--        <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>-->
          <el-button @click="resetForm('ruleForm')" style="width: 165px">重置</el-button>
          <el-button type="primary" @click="skipLogin('ruleForm')" style="width: 165px">登录</el-button>
          <!--        <el-button @click="showReg=!showReg">注册</el-button>-->
        </el-form-item>
      </el-form>
    </div>
  </div>

</template>

<script>
import axios from 'axios'
import ip from "../components/ip.js";
export default {
  name: "login",
  data() {
    return {
      showReg:false,
      ruleForm: {
        adminName: '',
        adminPasswd: ''
      },
      password:false,
      rules: {
        adminName: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 0, max: 10, message: '长度不高于10个字符', trigger: 'blur' }
        ],
        adminPasswd: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 0, max: 20, message: '长度不高于20个字符', trigger: 'blur' }
        ],
        // adminMail: [
        //   { required: true, message: '请输入邮箱', trigger: 'blur' },
        //   // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        // ],
      }
    };
  },
  methods: {
    // TODO 1：验证码
    // TODO 2：登录时需要进行数据库更新，更新该账号的最新登陆时间
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //TODO 输入正确性校验 并跳转至上传页面 且需要将用户名传给导航栏页面 进行用户的欢迎
          // axios.post('http://localhost:8085/admin/login',this.ruleForm).then(res=>{
          axios.post(ip+'/admin/login',this.ruleForm).then(res=>{
            if (res.data===true){
              // alert("欢迎！"+this.ruleForm.adminName)
              this.$refs[formName].resetFields();
              this.$router.push('/baseInfo')
            }
            else if (res.data==='此用户名不存在'){
              // alert(res.data)
              this.$refs[formName].resetFields();
            }
            else {
              // alert('密码错误！')
              this.ruleForm.adminPasswd=''
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    Reg(formName){
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // axios.post('http://localhost:8085/admin/login',this.ruleForm).then(res=>{
          axios.post(ip+'/admin/reg',this.ruleForm).then(res=>{
            if (res.data==='注册成功'){
              // alert(res.data)
              this.$refs[formName].resetFields();
              this.showReg=!this.showReg
            }
            else if (res.data==='用户名重复！请重新输入'){
              // alert(res.data)
              this.$refs[formName].resetFields();
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    skipLogin(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$router.push('/baseInfo')
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style scoped>
.card{
  position: absolute;
  width: 400px;
  left: 60%;
  top: 28%;
  /*left: 0;*/
  /*top: 0;*/
  color: #0ba3c2;
  height: 300px;
  /*max-width: 100%;*/
  /*padding: 60px 35px 0;*/
  margin: 0 auto;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid #4dcdfd;
  background-color: #194b85;
}

.title {
  font-size: 26px;
  margin: 0px -10px 10px 10px;
  text-align: center;
  font-weight: bold;
}
.title2 {
  font-size: 26px;
  height: 80px;
  line-height: 80px;
  /*margin: 0px -10px 10px 10px;*/
  text-align: center;
  font-weight: bold;
}
.main {
  /*background-color: #E9EEF3;*/
  background-image: url("../assets/background.jpg");
  background-repeat: no-repeat;
  /*background-attachment: fixed;*/
  /*background-size: cover;*/
  /*图片拉伸*/
  /*-moz-background-size:100% 100%;*/
  background-size:100% 100%;
  width: 100%;
  color: #333;
  text-align: center;
  line-height: 160px;
  height: 100vh;
}
.hand{
  position: absolute;
  left: 20%;
  top: 30%;
}
.handBg{
  position: absolute;
  left: 15%;
  top: 0;
  height: 100%;
}
.logo{
  position: absolute;
  left: 20%;
  top: 15%;
}

.test{
  position: absolute;
  left: 23%;
  top: 15%;
  color: #46a1ef;
  font-size: 40px;
  font-weight: bold;
  font-style: italic;
}
.cluster{
  position: absolute;
  left: 23.5%;
  top: 9.5%;
  font-size: 45px;
  color: #cdcdcd;
}
.el-header, .el-footer {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.secondAside {
  color: #333;
  text-align: center;
  line-height: 200px;
  background-image: url("../assets/handBg.png");
  background-repeat: no-repeat;
  /*background-size: cover;*/
  background-size:100% 100%;
}

.el-main {
  color: #333;
  text-align: center;
  line-height: 160px;
}
.el-container{
  position:absolute;
  top:0;
  left:0;
  height:100%;
  width:100%;
  background-image: url("../assets/云手机2期UI5.png");
  background-repeat: no-repeat;
  background-size: cover;
  overflow: hidden;
}

</style>
